package uk.co.droidinactu.sony.prst1.home.data;

import android.content.ContentValues;
import android.database.Cursor;
import android.provider.BaseColumns;

public final class Book extends AbstractDataObj {

    public static final String COLUMN_NAME_AUTHOR = "author";
    public static final String COLUMN_NAME_AUTHOR_KEY = "author_key";
    public static final String COLUMN_NAME_CONFORMS_TO = "conforms_to";
    public static final String COLUMN_NAME_CORRUPTED = "corrupted";
    public static final String COLUMN_NAME_DESCRIPTION = "description";
    public static final String COLUMN_NAME_EXPIRATION_DATE = "expiration_date";
    public static final String COLUMN_NAME_FILE_NAME = "file_name";
    public static final String COLUMN_NAME_FILE_PATH = "file_path";
    public static final String COLUMN_NAME_FILE_SIZE = "file_size";
    public static final String COLUMN_NAME_KANA_AUTHOR = "kana_author";
    public static final String COLUMN_NAME_KANA_PERIODICAL_NAME = "kana_periodical_name";
    public static final String COLUMN_NAME_KANA_TITLE = "kana_title";
    public static final String COLUMN_NAME_LOGOS = "logos";
    public static final String COLUMN_NAME_MIME_TYPE = "mime_type";
    public static final String COLUMN_NAME_PERIODICAL_NAME = "periodical_name";
    public static final String COLUMN_NAME_PERIODICAL_NAME_KEY = "periodical_name_key";
    public static final String COLUMN_NAME_PREVENT_DELETE = "prevent_delete";
    public static final String COLUMN_NAME_PUBLICATION_DATE = "publication_date";
    public static final String COLUMN_NAME_PURCHASED_DATE = "purchased_date";
    public static final String COLUMN_NAME_READING_TIME = "reading_time";
    public static final String COLUMN_NAME_SONY_ID = "sony_id";
    public static final String COLUMN_NAME_SOURCE_ID = "source_id";
    public static final String COLUMN_NAME_THUMBNAIL = "thumbnail";
    public static final String COLUMN_NAME_TITLE = "title";
    public static final String COLUMN_NAME_TITLE_KEY = "title_key";

    public long _id;
    public String author;
    public String author_key;
    public String conforms_to;
    public int corrupted;
    public String description;
    public int expiration_date;
    public String file_name;
    public String file_path;
    public long file_size;
    public String kana_author;
    public String kana_periodical_name;
    public String kana_title;
    public String logos;
    public String mime_type;
    public String periodical_name;
    public String periodical_name_key;
    public int prevent_delete;
    public int publication_date;
    public int purchased_date;
    public int reading_time;
    public String sony_id;
    public long source_id;
    public String thumbnail;
    public String title;
    public String title_key;

    public Book() {
    }

    public Book(final Cursor tmpCursor) {
        super(tmpCursor);
        try {
            _id = tmpCursor.getLong(tmpCursor.getColumnIndex(BaseColumns._ID));
        } catch (final Exception e) {
        }
        try {
            author = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_AUTHOR));
        } catch (final Exception e) {
        }
        try {
            author_key = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_AUTHOR_KEY));
        } catch (final Exception e) {
        }
        try {
            conforms_to = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_CONFORMS_TO));
        } catch (final Exception e) {
        }
        corrupted = tmpCursor.getInt(tmpCursor.getColumnIndex(COLUMN_NAME_CORRUPTED));
        description = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_DESCRIPTION));
        expiration_date = tmpCursor.getInt(tmpCursor.getColumnIndex(COLUMN_NAME_EXPIRATION_DATE));
        file_name = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_FILE_NAME));
        file_path = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_FILE_PATH));
        file_size = tmpCursor.getLong(tmpCursor.getColumnIndex(COLUMN_NAME_FILE_SIZE));
        kana_author = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_KANA_AUTHOR));
        kana_periodical_name = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_KANA_PERIODICAL_NAME));
        kana_title = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_KANA_TITLE));
        logos = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_LOGOS));
        mime_type = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_MIME_TYPE));
        periodical_name = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_PERIODICAL_NAME));
        periodical_name_key = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_PERIODICAL_NAME_KEY));
        prevent_delete = tmpCursor.getInt(tmpCursor.getColumnIndex(COLUMN_NAME_PREVENT_DELETE));
        publication_date = tmpCursor.getInt(tmpCursor.getColumnIndex(COLUMN_NAME_PUBLICATION_DATE));
        purchased_date = tmpCursor.getInt(tmpCursor.getColumnIndex(COLUMN_NAME_PURCHASED_DATE));
        reading_time = tmpCursor.getInt(tmpCursor.getColumnIndex(COLUMN_NAME_READING_TIME));
        sony_id = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_SONY_ID));
        source_id = tmpCursor.getInt(tmpCursor.getColumnIndex(COLUMN_NAME_SOURCE_ID));
        thumbnail = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_THUMBNAIL));
        title = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_TITLE));
        title_key = tmpCursor.getString(tmpCursor.getColumnIndex(COLUMN_NAME_TITLE_KEY));
    }

    @Override
    public ContentValues getContentValues() {
        final ContentValues map = super.getContentValues();
        map.put(COLUMN_NAME_AUTHOR, author);
        map.put(COLUMN_NAME_AUTHOR_KEY, author_key);
        map.put(COLUMN_NAME_CONFORMS_TO, conforms_to);
        map.put(COLUMN_NAME_CORRUPTED, corrupted);
        map.put(COLUMN_NAME_DESCRIPTION, description);
        map.put(COLUMN_NAME_EXPIRATION_DATE, expiration_date);
        map.put(COLUMN_NAME_FILE_NAME, file_name);
        map.put(COLUMN_NAME_FILE_PATH, file_path);
        map.put(COLUMN_NAME_FILE_SIZE, file_size);
        map.put(COLUMN_NAME_KANA_AUTHOR, kana_author);
        map.put(COLUMN_NAME_KANA_PERIODICAL_NAME, kana_periodical_name);
        map.put(COLUMN_NAME_KANA_TITLE, kana_title);
        map.put(COLUMN_NAME_LOGOS, logos);
        map.put(COLUMN_NAME_MIME_TYPE, mime_type);
        map.put(COLUMN_NAME_PERIODICAL_NAME, periodical_name);
        map.put(COLUMN_NAME_PERIODICAL_NAME_KEY, periodical_name_key);
        map.put(COLUMN_NAME_PREVENT_DELETE, prevent_delete);
        map.put(COLUMN_NAME_PUBLICATION_DATE, publication_date);
        map.put(COLUMN_NAME_PURCHASED_DATE, purchased_date);
        map.put(COLUMN_NAME_READING_TIME, reading_time);
        map.put(COLUMN_NAME_SONY_ID, sony_id);
        map.put(COLUMN_NAME_SOURCE_ID, source_id);
        map.put(COLUMN_NAME_THUMBNAIL, thumbnail);
        map.put(COLUMN_NAME_TITLE, title);
        map.put(COLUMN_NAME_TITLE_KEY, author);
        return map;
    }

    @Override
    public String getTableName() {
        return "books";
    }

    @Override
    public String toString() {
        return "book: " + title + " [by " + author + "]";
    }
}
